package test230529;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/5/28 23:19
 * 1137 第 N 个泰波那契数
 * https://leetcode.cn/problems/n-th-tribonacci-number/
 */
@SuppressWarnings({"all"})
public class Solution01 {

    public int tribonacci(int n) {
        if (n < 3) {
            return n == 0 ? n : 1;
        }
        int n0 = 0;
        int n1 = 1;
        int n2 = 1;
        int res = n0 + n1 + n2;
        for (int i = 3; i < n; i++) {
            n0 = n1;
            n1 = n2;
            n2 =res;
            res = n0 + n1 + n2;
        }
        return res;
    }
}